package com.titleevaluation.controller;

import com.titleevaluation.entity.IndustryQualifications;
import com.titleevaluation.service.IndustryQualificationsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/applications/{applicationId}/industry-qualifications")
public class IndustryQualificationsController {

    private final IndustryQualificationsService industryQualificationsService;

    public IndustryQualificationsController(IndustryQualificationsService industryQualificationsService) {
        this.industryQualificationsService = industryQualificationsService;
    }

    @PostMapping
    public ResponseEntity<IndustryQualifications> createIndustryQualifications(@PathVariable Long applicationId, @RequestBody IndustryQualifications industryQualifications) {
        IndustryQualifications createdIndustryQualifications = industryQualificationsService.createIndustryQualifications(applicationId, industryQualifications);
        return ResponseEntity.ok(createdIndustryQualifications);
    }

    @GetMapping
    public ResponseEntity<List<IndustryQualifications>> getIndustryQualificationsByApplicationId(@PathVariable Long applicationId) {
        List<IndustryQualifications> industryQualifications = industryQualificationsService.getIndustryQualificationsByApplicationId(applicationId);
        return ResponseEntity.ok(industryQualifications);
    }

    @GetMapping("/{id}")
    public ResponseEntity<IndustryQualifications> getIndustryQualificationsById(@PathVariable Long id) {
        return industryQualificationsService.getIndustryQualificationsById(id)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
    }

    @PutMapping("/{id}")
    public ResponseEntity<IndustryQualifications> updateIndustryQualifications(@PathVariable Long id, @RequestBody IndustryQualifications industryQualifications) {
        IndustryQualifications updatedIndustryQualifications = industryQualificationsService.updateIndustryQualifications(id, industryQualifications);
        return ResponseEntity.ok(updatedIndustryQualifications);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteIndustryQualifications(@PathVariable Long id) {
        industryQualificationsService.deleteIndustryQualifications(id);
        return ResponseEntity.noContent().build();
    }
}

